package com.qf.service.Impl;


import com.qf.mapper.ProductBatchesMapper;
import com.qf.model.ProductBatches;
import com.qf.page.PageResult;
import com.qf.page.QueryPageBean;
import com.qf.service.ProductBatchesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class ProductBatchesServiceImpl implements ProductBatchesService {
    @Autowired
    private ProductBatchesMapper productBatchesMapper;

    @Override
    public List<ProductBatches> findAll() {
        List<ProductBatches> list = productBatchesMapper.selectAll();
        return list;
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageResult pageResult =new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();//当前页
        Integer pageSize = queryPageBean.getPageSize();//每页大小
        List<ProductBatches> page = productBatchesMapper.findPage((currentPage-1)*pageSize,pageSize);
        long count = productBatchesMapper.count();
        pageResult.setRows(page);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public int add(ProductBatches productBatches) {
        int row = productBatchesMapper.insertProduct(productBatches);
        return row;
    }

    @Override
    public ProductBatches findById(int id) {
        ProductBatches productBatches = productBatchesMapper.findById(id);
        return productBatches;
    }

    @Override
    public int edit(ProductBatches productBatches) {
        int row = productBatchesMapper.update(productBatches);
        return row;
    }

    @Override
    public int deleteById(Integer id) {
        int row = productBatchesMapper.delById(id);
        return row;
    }
}